/*
 *
 *  * Copyright (c) 2016. For Intelligent Group.
 *
 */

package com.intelligent.mts.client.ex;

import javax.swing.*;
import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ImageObserver;
import java.awt.image.RenderedImage;
import java.awt.image.renderable.RenderableImage;
import java.text.AttributedCharacterIterator;
import java.util.Map;

/**
 * Created by Peter on 2016/7/27.
 */
public class JLabelUnderLinePerfect extends JLabel {

    private Color underLineColor;

    public JLabelUnderLinePerfect() {
        this("");
    }

    public JLabelUnderLinePerfect(String text) {
        super(text);
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        Rectangle r = g.getClipBounds();
        int xoffset = 0, yoffset = 0, pointX = 0, pointY = 0, point2X = 0, point2Y = 0;

        if (this.getBorder() != null && this.getBorder().getBorderInsets(this) != null) {
            Insets inserts = this.getBorder().getBorderInsets(this);
            xoffset = inserts.left;
            yoffset = inserts.bottom;
        }
        pointX = xoffset;
        pointY = point2Y = r.height - yoffset - getFontMetrics(getFont()).getDescent() + 1;
        point2X = pointX + getFontMetrics(getFont()).stringWidth(getText());
        System.out.println(pointX + "," + pointY +","+ point2X +","+point2Y);
        if (null != underLineColor) {
            g.setColor(underLineColor);
        }

        g.drawLine(pointX, pointY, point2X, point2Y);

    }


    public Color getUnderLineColor() {
        return underLineColor;
    }

    public void setUnderLineColor(Color pUnderLineColor) {
        underLineColor = pUnderLineColor;
    }

}
